/*
 * Copyright 2025 NXP
 * NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
 * accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
 * activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
 * comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
 * terms, then you may not retain, install, activate or otherwise use the software.
 */

#include "events_init.h"
#include <stdio.h>
#include "lvgl.h"

#include <stdio.h>
#include <time.h>

#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
#include "freemaster_client.h"
#endif

//==================================================公告功能模块事件

// 绘制表格
void draw_event_cb(lv_event_t *e)
{
    lv_draw_task_t *draw_task = lv_event_get_draw_task(e);
    lv_draw_dsc_base_t *base_dsc = lv_draw_task_get_draw_dsc(draw_task);
    /*If the cells are drawn...*/
    if (base_dsc->part == LV_PART_ITEMS)
    {
        uint32_t row = base_dsc->id1;
        uint32_t col = base_dsc->id2;

        /*Make the texts in the first cell center aligned*/
        if (row == 0)
        {
            lv_draw_label_dsc_t *label_draw_dsc = lv_draw_task_get_label_dsc(draw_task);
            if (label_draw_dsc)
            {
                label_draw_dsc->align = LV_TEXT_ALIGN_CENTER;
            }
            lv_draw_fill_dsc_t *fill_draw_dsc = lv_draw_task_get_fill_dsc(draw_task);
            if (fill_draw_dsc)
            {
                fill_draw_dsc->color = lv_color_mix(lv_palette_main(LV_PALETTE_BLUE), fill_draw_dsc->color, LV_OPA_50);
                fill_draw_dsc->opa = LV_OPA_COVER;
            }
        }
        /*In the first column align the texts to the right*/
        else if (col == 0)
        {
            lv_draw_label_dsc_t *label_draw_dsc = lv_draw_task_get_label_dsc(draw_task);
            if (label_draw_dsc)
            {
                label_draw_dsc->align = LV_TEXT_ALIGN_RIGHT;
            }
        }

        /*Make every 2nd row grayish*/
        if ((row != 0 && row % 2) == 0)
        {
            lv_draw_fill_dsc_t *fill_draw_dsc = lv_draw_task_get_fill_dsc(draw_task);
            if (fill_draw_dsc)
            {
                fill_draw_dsc->color = lv_color_mix(lv_palette_main(LV_PALETTE_GREY), fill_draw_dsc->color, LV_OPA_10);
                fill_draw_dsc->opa = LV_OPA_COVER;
            }
        }
    }
}

char is_english = 0;
void ddlist_event_handler(lv_event_t *e)
{

    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *obj = lv_event_get_target(e);
    switch (code)
    {
    case LV_EVENT_VALUE_CHANGED:
    {
        char str[10];
        lv_dropdown_get_selected_str(obj, str, sizeof(str));

        if (lv_obj_is_valid(guider_ui.screen_msgbox_1))
        {
            lv_msgbox_close(guider_ui.screen_msgbox_1);
        }

        if (lv_obj_is_valid(guider_ui.screen_msgbox_2))
        {
            lv_msgbox_close(guider_ui.screen_msgbox_2);
        }

        if (lv_strcmp(str, "中文") == 0)
        {
            lv_tabview_rename_tab(guider_ui.screen_tabview_1, 0, "景区地图");
            lv_tabview_rename_tab(guider_ui.screen_tabview_1, 1, "公告");
            lv_label_set_text(guider_ui.screen_menu_1_label_1, "景区");
            lv_label_set_text(guider_ui.screen_menu_1_label_2, "游乐设施");
            lv_label_set_text(guider_ui.screen_menu_1_label_3, "公共设施");
            static const char *screen_btnm_1_text_map[] = {
                "景点1",
                "\n",
                "古树",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_1, screen_btnm_1_text_map);
            static const char *screen_btnm_2_text_map[] = {
                "缆车",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_2, screen_btnm_2_text_map);
            static const char *screen_btnm_3_text_map[] = {
                "wifi",
                "\n",
                "公交",
                "\n",
                "停车场",
                "\n",
                "商店",
                "\n",
                "房屋",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_3, screen_btnm_3_text_map);
            is_english = 0;

            // 公告部分
            lv_label_set_text(guider_ui.screen_menu_2_label_1, "今日天气");
            lv_label_set_text(guider_ui.screen_menu_2_label_2, "风景介绍");
            lv_label_set_text(guider_ui.screen_menu_2_label_3, "设置");
            lv_label_set_text(guider_ui.screen_menu_2_label_4, "通知");

            lv_label_set_text(guider_ui.tianqi_label1, "晴天");
            lv_label_set_text(guider_ui.screen_btn_2_label, "取消");
            lv_label_set_text(guider_ui.screen_btn_1_label, "提交");
            lv_label_set_text(guider_ui.screen_label_2, "提交意见");
            lv_label_set_text(guider_ui.screen_label_3, "语言");

            lv_label_set_text(guider_ui.screen_label_1, "      欢迎来到翠峰山风景区                  您现在所处的位置是翠峰山风景区的入口，这里是探索自然美景和感受历史文化氛围的理想起点。");

            // table
            lv_table_set_cell_value(guider_ui.screen_table_1, 0, 0, "服务名称");
            lv_table_set_cell_value(guider_ui.screen_table_1, 1, 0, "景区入口");
            lv_table_set_cell_value(guider_ui.screen_table_1, 2, 0, "翠峰山自然");
            lv_table_set_cell_value(guider_ui.screen_table_1, 3, 0, "千年古树");
            lv_table_set_cell_value(guider_ui.screen_table_1, 4, 0, "缆车服务");
            lv_table_set_cell_value(guider_ui.screen_table_1, 5, 0, "免费公共WiFi");
            lv_table_set_cell_value(guider_ui.screen_table_1, 6, 0, "公共交通指南");
            lv_table_set_cell_value(guider_ui.screen_table_1, 7, 0, "停车场服务");
            lv_table_set_cell_value(guider_ui.screen_table_1, 8, 0, "24小时便利店");
            lv_table_set_cell_value(guider_ui.screen_table_1, 9, 0, "舒适住宿");

            lv_table_set_cell_value(guider_ui.screen_table_1, 0, 1, "详细介绍");
            lv_table_set_cell_value(guider_ui.screen_table_1, 1, 1, "开放时间：全年全天开放。门票价格：10元人民币。");
            lv_table_set_cell_value(guider_ui.screen_table_1, 2, 1, "无附加收费");
            lv_table_set_cell_value(guider_ui.screen_table_1, 3, 1, "无附加收费");
            lv_table_set_cell_value(guider_ui.screen_table_1, 4, 1, "服务时间：根据景区开放时间而定。收费标准：单程票价10元人民币。");
            lv_table_set_cell_value(guider_ui.screen_table_1, 5, 1, "服务时间：24小时。费用：免费。SSID: Cuifengshan_Free；密码: 'welcome2025'。");
            lv_table_set_cell_value(guider_ui.screen_table_1, 6, 1, "早 7:00 - 晚 10:30");
            lv_table_set_cell_value(guider_ui.screen_table_1, 7, 1, "服务时间：与景区开放时间一致。收费标准：免费停车，遵循先到先得的原则。");
            lv_table_set_cell_value(guider_ui.screen_table_1, 8, 1, "服务时间：24小时。费用：根据商品种类不同而变化。提供免费热水。");
            lv_table_set_cell_value(guider_ui.screen_table_1, 9, 1, "服务时间：入住时间为下午2点后，退房时间为中午12点前。收费标准：每晚50元人民币。");

            lv_label_set_text(guider_ui.info_label1, "景区地图");
            lv_label_set_text(guider_ui.info_label2, "缆车");
            lv_label_set_text(guider_ui.info_label3, "山");
        }
        else
        {
            lv_tabview_rename_tab(guider_ui.screen_tabview_1, 0, "Map");
            lv_tabview_rename_tab(guider_ui.screen_tabview_1, 1, "Announcement");
            lv_label_set_text(guider_ui.screen_menu_1_label_1, "Scenic");
            lv_label_set_text(guider_ui.screen_menu_1_label_2, "Rides");
            lv_label_set_text(guider_ui.screen_menu_1_label_3, "Public");

            static const char *screen_btnm_1_text_map[] = {
                "Scenic1",
                "\n",
                "trees",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_1, screen_btnm_1_text_map);
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_1, screen_btnm_1_text_map);
            static const char *screen_btnm_2_text_map[] = {
                "cable car",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_2, screen_btnm_2_text_map);
            static const char *screen_btnm_3_text_map[] = {
                "wifi",
                "\n",
                "Bus",
                "\n",
                "Parking lot",
                "\n",
                "Shop",
                "\n",
                "House",
                ""};
            lv_buttonmatrix_set_map(guider_ui.screen_btnm_3, screen_btnm_3_text_map);
            is_english = 1;

            // 公告部分
            lv_label_set_text(guider_ui.screen_menu_2_label_1, "Today's weather");
            lv_label_set_text(guider_ui.screen_menu_2_label_2, "Introduction to the scenery");
            lv_label_set_text(guider_ui.screen_menu_2_label_3, "Set up");
            lv_label_set_text(guider_ui.screen_menu_2_label_4, "Notice");
            lv_label_set_text(guider_ui.tianqi_label1, "Fine");

            lv_label_set_text(guider_ui.screen_btn_2_label, "Cancel");
            lv_label_set_text(guider_ui.screen_btn_1_label, "Submit");
            lv_label_set_text(guider_ui.screen_label_2, "Submit comments");

            lv_label_set_text(guider_ui.screen_label_3, "Language");

            lv_label_set_text(guider_ui.screen_label_1, "Welcome to Cuifeng Mountain Scenic Area    You are now at the entrance to the Cuifeng Mountain Scenic Area, an ideal starting point for exploring natural beauty and soaking up the historical and cultural atmosphere.");

            // table
            lv_table_set_cell_value(guider_ui.screen_table_1, 0, 0, "Service Name");
            lv_table_set_cell_value(guider_ui.screen_table_1, 1, 0, "Scenic Area Entrance");
            lv_table_set_cell_value(guider_ui.screen_table_1, 2, 0, "Cuifeng Mountain");
            lv_table_set_cell_value(guider_ui.screen_table_1, 3, 0, "Ancient Trees");
            lv_table_set_cell_value(guider_ui.screen_table_1, 4, 0, "Cable Car Service");
            lv_table_set_cell_value(guider_ui.screen_table_1, 5, 0, "Free Public WiFi");
            lv_table_set_cell_value(guider_ui.screen_table_1, 6, 0, "Public Transportation Guide");
            lv_table_set_cell_value(guider_ui.screen_table_1, 7, 0, "Parking Services");
            lv_table_set_cell_value(guider_ui.screen_table_1, 8, 0, "24-Hour Convenience Store");
            lv_table_set_cell_value(guider_ui.screen_table_1, 9, 0, "Comfortable Accommodation");

            lv_table_set_cell_value(guider_ui.screen_table_1, 0, 1, "Detailed Information");
            lv_table_set_cell_value(guider_ui.screen_table_1, 1, 1, "Opening Hours: Open 24/7. Admission Fee: 10 RMB per person.");
            lv_table_set_cell_value(guider_ui.screen_table_1, 2, 1, "free");
            lv_table_set_cell_value(guider_ui.screen_table_1, 3, 1, "free");
            lv_table_set_cell_value(guider_ui.screen_table_1, 4, 1, "Service Hours: According to scenic area opening times. Charges: 10 RMB for a one-way ticket.");
            lv_table_set_cell_value(guider_ui.screen_table_1, 5, 1, "Service Hours: Available 24 hours. Charges: Free. Network SSID: Cuifengshan_Free; Password: 'welcome2025'.");
            lv_table_set_cell_value(guider_ui.screen_table_1, 6, 1, "morning 7:00 - night 10:30");
            lv_table_set_cell_value(guider_ui.screen_table_1, 7, 1, "Service Hours: Aligns with the scenic area's opening hours. Charges: Free parking on a first-come, first-served basis.");
            lv_table_set_cell_value(guider_ui.screen_table_1, 8, 1, "Service Hours: Open 24 hours. Charges: Vary by product. Free hot water is provided.");
            lv_table_set_cell_value(guider_ui.screen_table_1, 9, 1, "Check-in Time: After 2 PM. Check-out Time: Before 12 PM. Charges: 50 RMB per night.");

            lv_label_set_text(guider_ui.info_label1, "map");
            lv_label_set_text(guider_ui.info_label2, "lanche");
            lv_label_set_text(guider_ui.info_label3, "shang");
        }
    }
    }
}

void text_area_btn_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *obj = lv_event_get_target(e);
    switch (code)
    {
    case LV_EVENT_CLICKED:
    {
        if (obj == guider_ui.screen_btn_1)
        {
            goto submit;
        }
        else
        {
            lv_textarea_set_text(guider_ui.screen_ta_1, "");
            return;
        }
        break;
    }
    case LV_EVENT_READY:
    {
        goto submit;
    }
    }

submit:
    lv_obj_add_flag(guider_ui.keyboard, LV_OBJ_FLAG_HIDDEN);
    if (lv_obj_is_valid(guider_ui.screen_msgbox_2))
        lv_msgbox_close(guider_ui.screen_msgbox_2);

    guider_ui.screen_msgbox_2 = lv_msgbox_create(guider_ui.screen_menu_2_subpage_3_cont);
    lv_msgbox_add_close_button(guider_ui.screen_msgbox_2);
    lv_obj_set_pos(guider_ui.screen_msgbox_2, 0, -50);
    if (is_english)
    {
        lv_msgbox_add_title(guider_ui.screen_msgbox_2, "submit succeed");
        lv_msgbox_add_text(guider_ui.screen_msgbox_2, "submit succeed");
    }
    else
    {
        lv_msgbox_add_title(guider_ui.screen_msgbox_2, "提交成功");
        lv_msgbox_add_text(guider_ui.screen_msgbox_2, "提交成功");
    }

    // 获取系统时间
    time_t rawtime;
    struct tm *info;
    char date_y_m_d_h_m_s[80];
    time(&rawtime);
    info = gmtime(&rawtime);
    sprintf(date_y_m_d_h_m_s, "%d/%d/%d %d:%d:%d", 1900 + info->tm_year, 1 + info->tm_mon, info->tm_mday, 8 + info->tm_hour, info->tm_min, info->tm_sec);
    char str[1024];
    lv_strcpy(str, lv_textarea_get_text(guider_ui.screen_ta_1));
    lv_textarea_set_text(guider_ui.screen_ta_1, "");

    FILE *fp = fopen("advice.txt", "a+");
    fprintf(fp, "%s\n%s\n", date_y_m_d_h_m_s, str);
    fclose(fp);
}

lv_image_dsc_t **animing[5][9] = {
    {
        &screen_animimg_11_0,
        &screen_animimg_11_1,
        &screen_animimg_11_2,
        &screen_animimg_11_3,
        &screen_animimg_11_4,
        &screen_animimg_11_5,
        &screen_animimg_11_6,
        &screen_animimg_11_7,
        &screen_animimg_11_8,
    },
    {
        &screen_animimg_22_0,
        &screen_animimg_22_1,
        &screen_animimg_22_2,
        &screen_animimg_22_3,
        &screen_animimg_22_4,
        &screen_animimg_22_5,
        &screen_animimg_22_6,
        &screen_animimg_22_7,
        &screen_animimg_22_8,
    },
    {
        &screen_animimg_33_3,
        &screen_animimg_33_4,
        &screen_animimg_33_18,
        &screen_animimg_33_19,
        &screen_animimg_33_20,
        &screen_animimg_33_21,
        &screen_animimg_33_22,
        &screen_animimg_33_23,
        &screen_animimg_33_24,
    },
    {
        &screen_animimg_44_1,
        &screen_animimg_44_2,
        &screen_animimg_44_3,
        &screen_animimg_44_10,
        &screen_animimg_44_11,
        &screen_animimg_44_12,
        &screen_animimg_44_13,
        &screen_animimg_44_14,
        &screen_animimg_44_15,
    },
    {
        &screen_animimg_55_0,
        &screen_animimg_55_1,
        &screen_animimg_55_2,
        &screen_animimg_55_10,
        &screen_animimg_55_11,
        &screen_animimg_55_12,
        &screen_animimg_55_13,
        &screen_animimg_55_14,
        &screen_animimg_55_15,
    }};

// 如果是255则切换下一张 否则是指定动画
void change_animing(unsigned char index)
{
    static char num = 0;
    if (index != 255 && index > 4)
        return;
    if (index == 255)
        num++;
    else
        num = index;
    num %= 5;
    lv_animimg_set_src(guider_ui.screen_animimg_1, animing[num], 9);
}

static void screen_list_btn_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *obj = lv_event_get_target(e);
    switch (code)
    {
    case LV_EVENT_CLICKED:
    {
        if (obj == guider_ui.screen_list_1_item0)
        {
            change_animing(0);
        }
        if (obj == guider_ui.screen_list_1_item1)
        {
            change_animing(1);
        }
        if (obj == guider_ui.screen_list_1_item2)
        {
            change_animing(2);
        }
        if (obj == guider_ui.screen_list_1_item3)
        {
            change_animing(3);
        }
        if (obj == guider_ui.screen_list_1_item4)
        {
            change_animing(4);
        }
    }
    }
}

//==================================================景区地图功能模块事件
// 图标枚举
typedef enum
{
    ICON_PEOPLE = 0,
    ICON_TINGCHECHANG,
    ICON_LANCHE,
    ICON_SHANG,
    ICON_GONJIAO,
    ICON_CHAOSHI,
    ICON_FANGWU,
    ICON_GUSHU,
    ICON_WIFI
} IconType;

// 更新图标显示状态
static void select_icon(lv_ui *ui, char *selects)
{

    int icon_num = 9;
    // 图标对象数组
    lv_obj_t *icons[] = {
        guider_ui.screen_people,
        guider_ui.screen_tingchechang,
        guider_ui.screen_lanche,
        guider_ui.screen_shang,
        guider_ui.screen_gonjiao,
        guider_ui.screen_chaoshi,
        guider_ui.screen_fangwu,
        guider_ui.screen_gushu,
        guider_ui.screen_wifi};

    // 隐藏所有图标 后续根据selects选择显示什么图标
    lv_obj_add_flag(ui->screen_people, LV_OBJ_FLAG_HIDDEN);

    for (int i = 0; i < icon_num; i++)
    {
        lv_obj_add_flag(icons[i], LV_OBJ_FLAG_HIDDEN);
    }

    if (selects == NULL)
        return;

    // 根据 selects 数组显示对应的图标
    for (int i = 0; i < icon_num; i++)
    {
        if (selects[i] != 0)
        {
            lv_obj_remove_flag(icons[i], LV_OBJ_FLAG_HIDDEN);
        }
    }
}

static void screen_btnm_event_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *obj = lv_event_get_target(e);
    switch (code)
    {
    case LV_EVENT_VALUE_CHANGED:
    {
        // 声明标志位数组，每个元素对应一个图标是否被选中
        static char selected[9] = {1};
        unsigned char id = lv_buttonmatrix_get_selected_button(obj);
        char *txt = lv_buttonmatrix_get_button_text(obj, id);

        // 根据按钮文本确定对应的图标类型
        if (lv_strcmp(txt, "景点1") == 0 || lv_strcmp(txt, "Scenic1") == 0)
        {
            selected[ICON_SHANG] = !selected[ICON_SHANG];
        }
        if (lv_strcmp(txt, "缆车") == 0 || lv_strcmp(txt, "cable car") == 0)
        {
            selected[ICON_LANCHE] = !selected[ICON_LANCHE];
        }
        if (lv_strcmp(txt, "古树") == 0 || lv_strcmp(txt, "trees") == 0)
        {
            selected[ICON_GUSHU] = !selected[ICON_GUSHU];
        }
        if (lv_strcmp(txt, "wifi") == 0)
        {
            selected[ICON_WIFI] = !selected[ICON_WIFI];
        }
        if (lv_strcmp(txt, "公交") == 0 || lv_strcmp(txt, "Bus") == 0)
        {
            selected[ICON_GONJIAO] = !selected[ICON_GONJIAO];
        }
        if (lv_strcmp(txt, "停车场") == 0 || lv_strcmp(txt, "Parking lot") == 0)
        {
            selected[ICON_TINGCHECHANG] = !selected[ICON_TINGCHECHANG];
        }
        if (lv_strcmp(txt, "商店") == 0 || lv_strcmp(txt, "Shop") == 0)
        {
            selected[ICON_CHAOSHI] = !selected[ICON_CHAOSHI];
        }
        if (lv_strcmp(txt, "房屋") == 0 || lv_strcmp(txt, "House") == 0)
        {
            selected[ICON_FANGWU] = !selected[ICON_FANGWU];
        }

        // 调用 select_icon 更新显示
        select_icon(&guider_ui, selected);
        break;
    }
    default:
        break;
    }
}

static void msgbox_init(lv_ui *ui)
{
    if (lv_obj_is_valid(ui->screen_msgbox_1)) // 一次只能存在一个消息对象
        lv_msgbox_close(ui->screen_msgbox_1);

    ui->screen_msgbox_1 = lv_msgbox_create(ui->screen_cont_2);
    lv_obj_set_pos(ui->screen_msgbox_1, 100, 0);
    lv_obj_set_size(ui->screen_msgbox_1, 487, 361);
    lv_obj_t *screen_msgbox_1_close_btn = lv_msgbox_add_close_button(ui->screen_msgbox_1);

    // Write style for screen_msgbox_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
    lv_obj_set_style_bg_opa(ui->screen_msgbox_1, 80, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->screen_msgbox_1, lv_color_hex(0x343a3f), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->screen_msgbox_1, LV_GRAD_DIR_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui->screen_msgbox_1, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_opa(ui->screen_msgbox_1, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui->screen_msgbox_1, lv_color_hex(0x575757), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(ui->screen_msgbox_1, LV_BORDER_SIDE_FULL, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(ui->screen_msgbox_1, 18, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(ui->screen_msgbox_1, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    // Write style state: LV_STATE_DEFAULT for &style_screen_msgbox_1_extra_title_main_default
    static lv_style_t style_screen_msgbox_1_extra_title_main_default;
    ui_init_style(&style_screen_msgbox_1_extra_title_main_default);

    lv_style_set_text_color(&style_screen_msgbox_1_extra_title_main_default, lv_color_hex(0x000000));
    lv_style_set_text_font(&style_screen_msgbox_1_extra_title_main_default, &lv_font_montserratMedium_19);
    lv_style_set_text_opa(&style_screen_msgbox_1_extra_title_main_default, 255);
    lv_style_set_text_letter_space(&style_screen_msgbox_1_extra_title_main_default, 0);
    lv_style_set_text_line_space(&style_screen_msgbox_1_extra_title_main_default, 30);
    lv_obj_add_style(lv_msgbox_get_header(ui->screen_msgbox_1), &style_screen_msgbox_1_extra_title_main_default, LV_PART_MAIN | LV_STATE_DEFAULT);

    // Write style state: LV_STATE_DEFAULT for &style_screen_msgbox_1_extra_content_main_default
    static lv_style_t style_screen_msgbox_1_extra_content_main_default;
    ui_init_style(&style_screen_msgbox_1_extra_content_main_default);

    lv_style_set_text_color(&style_screen_msgbox_1_extra_content_main_default, lv_color_hex(0xffffff));
    lv_style_set_text_font(&style_screen_msgbox_1_extra_content_main_default, &lv_font_montserratMedium_19);
    lv_style_set_text_opa(&style_screen_msgbox_1_extra_content_main_default, 255);
    lv_style_set_text_letter_space(&style_screen_msgbox_1_extra_content_main_default, 0);
    lv_style_set_text_line_space(&style_screen_msgbox_1_extra_content_main_default, 10);
    lv_obj_add_style(lv_msgbox_get_content(ui->screen_msgbox_1), &style_screen_msgbox_1_extra_content_main_default, LV_PART_MAIN | LV_STATE_DEFAULT);

    // Write style state: LV_STATE_DEFAULT for &style_screen_msgbox_1_extra_btns_items_default
    static lv_style_t style_screen_msgbox_1_extra_btns_items_default;
    ui_init_style(&style_screen_msgbox_1_extra_btns_items_default);

    lv_style_set_bg_opa(&style_screen_msgbox_1_extra_btns_items_default, 0);
    lv_style_set_border_width(&style_screen_msgbox_1_extra_btns_items_default, 2);
    lv_style_set_border_opa(&style_screen_msgbox_1_extra_btns_items_default, 255);
    lv_style_set_border_color(&style_screen_msgbox_1_extra_btns_items_default, lv_color_hex(0x299d9c));
    lv_style_set_border_side(&style_screen_msgbox_1_extra_btns_items_default, LV_BORDER_SIDE_FULL);
    lv_style_set_radius(&style_screen_msgbox_1_extra_btns_items_default, 4);
    lv_style_set_text_color(&style_screen_msgbox_1_extra_btns_items_default, lv_color_hex(0x01798e));
    lv_style_set_text_font(&style_screen_msgbox_1_extra_btns_items_default, &lv_font_Alatsi_Regular_13);
    lv_style_set_text_opa(&style_screen_msgbox_1_extra_btns_items_default, 255);
}

static void screen_msgbox_show_information_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *target = lv_event_get_target(e);
    switch (code)
    {
    case LV_EVENT_CLICKED:
    {
        lv_obj_t *obj = lv_event_get_target(e);
        msgbox_init(&guider_ui);
        if (target == guider_ui.screen_people)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Welcome to Cuifengshan Scenic Area");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "You are now at the entrance of Cuifengshan Scenic Area, an ideal starting point for exploring natural beauty and experiencing a historical atmosphere.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "欢迎来到翠峰山风景区");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "您现在所处的位置是翠峰山风景区的入口，这里是探索自然美景和感受历史文化氛围的理想起点。");
            }

            lv_image_t *msg_img = lv_image_create(guider_ui.screen_msgbox_1);
            lv_obj_center(msg_img);
            lv_obj_set_size(msg_img, 480, 200);
            lv_image_set_src(msg_img, &shang);
        }
        else if (target == guider_ui.screen_shang)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Cuifeng Mountain - The Intersection of Nature and History");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "Renowned for its magnificent natural scenery, Cuifeng Mountain is home to a rich variety of flora and fauna. With a history dating back hundreds of years, this mountain has witnessed countless stories and changes.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "翠峰山——自然与历史的交汇点");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "翠峰山以其壮丽的自然风光而著称，拥有丰富的动植物资源。这座山脉的历史可以追溯到几百年前，它见证了无数的故事和变迁。");
            }
        }
        else if (target == guider_ui.screen_gushu)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Ancient Trees - Witnesses of Life");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "In Cuifeng Mountain, you can find some ancient trees that have witnessed the passage of time. These trees are not only wonders of nature but also sacred objects in the hearts of local residents, carrying many legends and stories, adding a touch of mystery to this land.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "千年古树——生命的见证者");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "在翠峰山中，您可以找到一些古老的树木，它们见证了岁月的流转。这些树木不仅是自然界的奇迹，也是当地居民心中的圣物。它们承载着许多传说和故事，为这片土地增添了神秘色彩。");
            }
        }
        else if (target == guider_ui.screen_lanche)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Convenient Cable Car Service");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "To let visitors easily enjoy the beautiful views from the top, Cuifeng Mountain offers convenient cable car services. For just 10 RMB, you can enjoy a quick transportation option between the foot and the peak of the mountain, saving your energy and providing stunning aerial views of the entire area.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "便捷缆车服务");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "为了让游客能够轻松地享受山顶的美景，翠峰山提供了便捷的缆车服务。只需支付10元人民币，您就可以享受到往返于山脚和山顶之间的快速交通方式。这不仅节省了体力，还让您有机会从空中俯瞰整个山区的壮丽景色。");
            }

            lv_image_t *msg_img = lv_image_create(guider_ui.screen_msgbox_1);
            lv_obj_center(msg_img);
            lv_obj_set_size(msg_img, 480, 200);
            lv_image_set_src(msg_img, &lanche);
        }
        else if (target == guider_ui.screen_wifi)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Free Public WiFi");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "For a more convenient travel experience, multiple public WiFi hotspots are available within Cuifengshan Scenic Area. Connect to our network (SSID: Cuifengshan_Free) with the password 'welcome2025' to share your travel experiences or look up needed information anytime.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "免费公共WiFi");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "为了让您的旅行更加便利，翠峰山风景区内设有多个公共WiFi热点。连接我们的网络（SSID: Cuifengshan_Free），密码为'welcome2025'，即可随时分享您的旅行经历或查找所需的信息。");
            }
        }
        else if (target == guider_ui.screen_gonjiao)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Public Transportation Guide");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "If you choose to come by bus, get off at the nearest bus stop. There is a detailed schedule here for your reference to ensure you plan your arrival time accurately.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "公共交通指南");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "如果您选择乘坐公交车前来游览，可以在最近的公交站下车。这里有详细的行程表供您参考，确保您能准确规划到达时间。");
            }
        }
        else if (target == guider_ui.screen_tingchechang)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Parking Services");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "For self-drive travelers, we offer a spacious free parking lot. First-come-first-served basis applies, so please arrive early to secure a spot.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "停车场服务");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "对于自驾游的朋友来说，我们提供了一个宽敞的免费停车场。遵循先到先得的原则，请尽早到达以确保停车位。");
            }
        }
        else if (target == guider_ui.screen_chaoshi)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "24-Hour Convenience Store");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "No matter when or where, you can find what you need at our 24-hour convenience store. Here, not only are various daily necessities sold, but free hot water is also provided for your convenience.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "24小时便利店");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "无论何时何地，您都可以在我们的24小时便利店找到所需的商品和服务。这里不仅出售各种日常用品，还提供免费热水，方便您随时补充水分。");
            }
        }
        else if (target == guider_ui.screen_fangwu)
        {
            if (is_english)
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "Comfortable Accommodation");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "The lodges located within the scenic area provide a comfortable resting place. Whether for short stays or long-term residence, they meet all your needs. Accommodation fees are 50 RMB per day, offering great value for money.");
            }
            else
            {
                lv_msgbox_add_title(guider_ui.screen_msgbox_1, "舒适住宿");
                lv_msgbox_add_text(guider_ui.screen_msgbox_1, "位于风景区内的旅馆为您提供了一个舒适的休息场所。无论是短期停留还是长期居住，这里都能满足您的需求。住宿费用为每天50元人民币，性价比极高。");
            }
        }

        break;
    }
    default:
        break;
    }
}

static void screen_label_area_select_event_handler(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code)
    {
    case LV_EVENT_CLICKED:
    {
        static unsigned char flag = 0;
        flag++;
        flag %= 2;
        if (flag == 1)
        {
            lv_obj_remove_flag(guider_ui.screen_menu_1, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(guider_ui.screen_menu_1, LV_OBJ_FLAG_HIDDEN);
        }
        break;
    }
    default:
        break;
    }
}

void screen_init_list_btn(lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_list_1_item0, screen_list_btn_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_list_1_item1, screen_list_btn_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_list_1_item2, screen_list_btn_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_list_1_item3, screen_list_btn_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_list_1_item4, screen_list_btn_handler, LV_EVENT_ALL, ui);
}

void events_init_btnm(lv_ui *ui)
{
    // 先将图标全部隐藏 或者可以选择要显示的系列图标
    // char select_icons[] = {0,1,2,3};
    // char *select_icons = NULL;
    char select_icons[9] = {1}; // 仅显示游客
    select_icon(ui, select_icons);
    // 为按钮组添加可选中状态
    lv_buttonmatrix_set_button_ctrl_all(ui->screen_btnm_1, LV_BUTTONMATRIX_CTRL_CHECKABLE);
    lv_buttonmatrix_set_button_ctrl_all(ui->screen_btnm_2, LV_BUTTONMATRIX_CTRL_CHECKABLE);
    lv_buttonmatrix_set_button_ctrl_all(ui->screen_btnm_3, LV_BUTTONMATRIX_CTRL_CHECKABLE);

    lv_obj_add_event_cb(ui->screen_btnm_1, screen_btnm_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_btnm_2, screen_btnm_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_btnm_3, screen_btnm_event_handler, LV_EVENT_ALL, ui);
}

void events_init_msg(lv_ui *ui)
{
    lv_obj_add_event(ui->screen_people, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_tingchechang, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_lanche, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_shang, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_gonjiao, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_chaoshi, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_fangwu, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_wifi, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event(ui->screen_gushu, screen_msgbox_show_information_handler, LV_EVENT_ALL, ui);
}

void events_init_screen(lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_label_area_select, screen_label_area_select_event_handler, LV_EVENT_ALL, ui);
}

void events_init(lv_ui *ui)
{
}
